﻿using Publicuse.Entity;
using Publicuse.Util;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Publicuse.Export
{
    /// <summary>
    /// 通知公告管理信息导出辅助类
    /// </summary>
    public class NoticeanExport
    {
        /// <summary>
        /// 通知公告管理导出数据设置
        /// </summary>
        /// <param name="excelName"></param>
        /// <param name="fileName"></param>
        /// <param name="list"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static MemoryStream ExportData(string fileName, string excelName, List<Noticean> list, out string msg)
        {
            msg = string.Empty;
            MemoryStream ms = ExcelUtil.GetExcelUtil.InitExportData(fileName, excelName, list, (row, cell, sheet1, TextSytle, srow, hssfworkbookDown) =>
            {

                foreach (Noticean item in list)
                {
                    srow++;
                    row = sheet1.CreateRow(srow);
                    //标题
                    cell = row.CreateCell(0);
                    cell.CellStyle = TextSytle;
                    cell.SetCellValue(item.title);
                    //类型
                    cell = row.CreateCell(1);
                    cell.CellStyle = TextSytle;
                    cell.SetCellValue(item.type);
                    //内容
                    cell = row.CreateCell(2);
                    cell.CellStyle = TextSytle;
                    cell.SetCellValue(item.content);
                    //已读用户
                    cell = row.CreateCell(3);
                    cell.CellStyle = TextSytle;
                    cell.SetCellValue(item.readornot);
                    //发布人
                    cell = row.CreateCell(4);
                    cell.CellStyle = TextSytle;
                    cell.SetCellValue(item.publisher);
                    //创建时间
                    cell = row.CreateCell(5);
                    cell.CellStyle = TextSytle;
                    cell.SetCellValue(item.cTime.ToString("yyyy-MM-dd HH:mm:ss"));
                    //描述
                    cell = row.CreateCell(6);
                    cell.CellStyle = TextSytle;
                    cell.SetCellValue(item.Remark);
                    //发布状态
                    cell = row.CreateCell(7);
                    cell.CellStyle = TextSytle;
                    cell.SetCellValue(item.status == 1 ? "未发布" : "已发布");
                }
            }, out msg, 2, true);
            return ms;
        }
    }
}
